package com.agileboot.attendance.controller;

import com.agileboot.attendance.domain.settlement.dto.SettlementApproveDTO;
import com.agileboot.attendance.domain.settlement.dto.SettlementBillDTO;
import com.agileboot.attendance.domain.settlement.dto.SettlementBillQuery;
import com.agileboot.attendance.domain.settlement.dto.SettlementBillRequest;
import com.agileboot.attendance.domain.settlement.service.SettlementApproveService;
import com.agileboot.attendance.domain.settlement.service.SettlementService;
import com.agileboot.common.core.base.BaseController;
import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.common.core.page.PageDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 结算单管理
 */
@Api(tags = "结算单管理")
@RestController
@RequestMapping("/settlement")
@RequiredArgsConstructor
public class SettlementController extends BaseController {

    private final SettlementService settlementService;
    private final SettlementApproveService approveService;

    @ApiOperation("结算单列表")
    @GetMapping("/list")
    public ResponseDTO<PageDTO<SettlementBillDTO>> list(SettlementBillQuery query) {
        PageDTO<SettlementBillDTO> pageData = settlementService.list(query);
        return ResponseDTO.ok(pageData);
    }

    @ApiOperation("结算单详情")
    @GetMapping("/{id}")
    public ResponseDTO<SettlementBillDTO> getInfo(@PathVariable Long id) {
        SettlementBillDTO billDTO = settlementService.getInfo(id);
        return ResponseDTO.ok(billDTO);
    }

    @ApiOperation("新增结算单")
    @PostMapping
    public ResponseDTO<Long> add(@RequestBody @Validated SettlementBillRequest request) {
        Long id = settlementService.add(request);
        return ResponseDTO.ok(id);
    }

    @ApiOperation("修改结算单")
    @PutMapping
    public ResponseDTO<Void> update(@RequestBody @Validated SettlementBillRequest request) {
        settlementService.update(request);
        return ResponseDTO.ok();
    }

    @ApiOperation("删除结算单")
    @DeleteMapping("/{ids}")
    public ResponseDTO<Void> delete(@PathVariable Long[] ids) {
        settlementService.delete(ids);
        return ResponseDTO.ok();
    }

    @ApiOperation("提交审核")
    @PostMapping("/{id}/submit")
    public ResponseDTO<Void> submitReview(@PathVariable Long id) {
        settlementService.submitReview(id);
        return ResponseDTO.ok();
    }

    @ApiOperation("审核结算单")
    @PostMapping("/approve")
    public ResponseDTO<Void> approve(@RequestBody @Validated SettlementApproveDTO approveDTO) {
        settlementService.approve(approveDTO);
        return ResponseDTO.ok();
    }

    @ApiOperation("获取结算单号选项")
    @GetMapping("/billno/options")
    public ResponseDTO<List<Map<String, String>>> getBillNoOptions() {
        List<Map<String, String>> options = settlementService.getBillNoOptions();
        return ResponseDTO.ok(options);
    }
}
